package main

import (
	"fmt"
	"time"
)

func newTimer() {
	myTimer := time.NewTimer(5 * time.Second)
	defer myTimer.Stop()
	for {
		select {
		case <-myTimer.C:
			fmt.Println("到时候了。。。")
			// 重置定时器
			myTimer.Reset(5 * time.Second)
		default:
			fmt.Println("还没到时候")
			time.Sleep(1 * time.Second)
		}
	}
}

func newTicker() {
	myTicker := time.NewTicker(5 * time.Second)
	for {
		select {
		case <-myTicker.C:
			fmt.Println("到期了。。。")
		default:
			fmt.Println("还没到时候")
			time.Sleep(1 * time.Second)
		}
	}
}

func main() {
	// newTimer()
	newTicker()
}
